//
//  AgreementViewController.m
//  XYMaterial
//
//  Created by 肖扬 on 16/1/9.
//  Copyright © 2016年 肖扬. All rights reserved.
//

#import "AgreementViewController.h"
#import "JSONKit.h"
#import "baseNavView.h"
@interface AgreementViewController ()<UIScrollViewDelegate>{
    UIScrollView *scroll;
}

@end

@implementation AgreementViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    baseNavView *nav = [[baseNavView alloc]initWithFrame:CGRectMake(0, 0, SWIDTH, 64)];
    [nav setBackgroundColor:[UIColor clearColor]];
    [self.view addSubview:nav];
    [nav.title setText:@"用户协议"];
    [nav.left addTarget: self action: @selector(backClick:) forControlEvents: UIControlEventTouchUpInside];
    TIME
    HEADDIC(nowTime, @"/protocol/index")
    NSDictionary *body = [NSDictionary dictionary];
    NSMutableDictionary *dic = [NSMutableDictionary dictionary];
    [dic setObject:body forKey:@"body"];
    [dic setObject:HEAD forKey:@"head"];
    requestManage *request = [[requestManage alloc]init];
    NSString *result = [request post:APPIP postDataDic:dic error:nil];
    NSMutableDictionary *dataResult = [result objectFromJSONString];
    NSString *data = [[dataResult objectForKey:@"data"] objectForKey:@"html"];
    
    scroll = [[UIScrollView alloc]initWithFrame:CGRectMake(0, 64, SWIDTH, VHEIGHT)];
    scroll.backgroundColor = [UIColor whiteColor];
    [self.view addSubview:scroll];

    UILabel *label = [[UILabel alloc]initWithFrame:CGRectMake(10, 0, SWIDTH-20, VHEIGHT)];
    label.numberOfLines = 0;
    label.lineBreakMode = NSLineBreakByWordWrapping;
    label.font = [UIFont systemFontOfSize:14];
    [scroll addSubview:label];
    dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
        dispatch_async(dispatch_get_main_queue(), ^{
            label.text = data;
            CGSize size = [label sizeThatFits:CGSizeMake(SWIDTH-20, MAXFLOAT)];
            label.frame =CGRectMake(10, 0, SWIDTH-20, size.height);
            [scroll setContentSize:CGSizeMake(SWIDTH, size.height+30)];
        });
    });
    
    // Do any additional setup after loading the view.
}
-(void)backClick:(UIButton *)sender{
    [self.navigationController popViewControllerAnimated:YES];
}
- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
